<?php
/** 
 * EGP Framework
 *
 * LICENSE
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 * @author     Akon(番茄红了) <aultoale@gmail.com>
 * @copyright  Copyright (c) 2008 (http://www.tblog.com.cn)
 * @license    http://www.gnu.org/licenses/gpl.html     GPL 3
 * @version    v1.0.0 Beta @ 2008-10-16
 */

!defined('EGP_LIB_DIR') && die('Access Deny!');

/**
 * APC 缓存驱动
 *
 * @package    classes
 * @author     Akon(番茄红了) <aultoale@gmail.com>
 * @copyright  Copyright (c) 2008 (http://www.tblog.com.cn)
 * @license    http://www.gnu.org/licenses/gpl.html     GPL 3
 */
class EGP_Cache_Apc extends EGP_Cache_Abstract {

    /**
     * 构造函数
     *
     * @param  array  $options
     * @throws EGP_Exception
     */
    public function __construct(array $options = array())
    {
        if (!extension_loaded('apc'))
            throw new EGP_Exception('PHP APC 扩展尚未有效安装，请检查 "php.ini"');
        parent::__construct($options);
    }

    /**
     * 保存缓存资料
     *
     * @param  mixed   $data
     * @param  string  $id
     * @return boolean
     */
    public function save($data, $id)
    {
        return apc_store($id, $data, $this->_options['life_time']);
    }

    /**
     * 加载缓存数据
     *
     * @param  string   $id
     * @return mixed|false
     */
    public function load($id)
    {
        return apc_fetch($id);
    }

    /**
     * 移除缓存数据
     *
     * @param  string  $name
     * @return boolean
     */
    public function remove($id)
    {
        return apc_delete($id);
    }

    /**
     * 移除所有缓存数据
     *
     * @return boolean
     */
    public function clean()
    {
        return apc_clear_cache('user');
    }

}